#ifndef ETHERCAT_MOTOR_CONTROL_H
#define ETHERCAT_MOTOR_CONTROL_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <jansson.h>




// Global variables

// Motor structure definition
typedef struct {
    int ethercatid;
    int type; // 0: servo, 1: other types
    int target_position;
    int velocity;
    int acceleration;
    int deceleration;
    int current_position;
    int status;
    int current_speed;
    int current_torque;
    int is_running; // 0: stopped, 1: running
} Motor_or_IO;

// Global motor array
extern Motor_or_IO devices[128];

extern int slaveid;
extern int target_position;
extern int speed;

extern char netcard[64]; // Default network interface
extern int slave_count;   // Number of motors

// Function declarations
void delay_ms(int milliseconds);
void enable_motor(int slave_position);
int enable_all_motors();
int read_all_motors();
int SV630N(int slave_position, int target_position, int profile_velocity);
int doStop(int slave_position);
int doStop1(int slave_position);
int doStop2(int slave_position);
void read_config(const char *config_file);
int init_soem(int argc, char *argv[]);

#endif // ETHERCAT_MOTOR_CONTROL_H